
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
 // ERROR: Not supported in C#: OptionDeclaration
namespace NCS_CS
{
	internal class CjxtlN
	{
		private _CCard card1;
		double deltaPrevPrevPower;
		double deltaPrevPower;
		double deltaPower;
		double PrevOutV;
			//OUTC = 2
		int outc;
			//= method1.c.chanel
		int getC;
		double pidP;
		int COUNT;

		public void setGetOut( int g,  int o)
		{
			outc = o;
			getC = g;
		}
		public void setCard(ref _CCard v)
		{
			card1 = v;
		}
		public void setpidp(ref double v)
		{
			pidP = v;
		}


		public double PID(double powerset)
		{
			double outv = 0;
			double tmp = 0;
			//STATIC 用于累加
			COUNT = COUNT + 1;
			if (COUNT % 50 == 0) {
				static_PID_power = static_PID_power + card1.getchanelVolt(getC);
				static_PID_power = static_PID_power / 50;
				//采用平均值
				deltaPower = powerset - static_PID_power;
				tmp = tmp + 0.3F * deltaPower - 0.2F * deltaPrevPower + 0.0625F * deltaPrevPrevPower;
				outv = PrevOutV + pidP * tmp;
				//.13 _.15* tmp '输出电压 为 检测电压变化量的二倍
				if (outv > 5) {
					outv = 5;
				}
				if (outv < 0) {
					outv = 0;
				}
				card1.newDA(outc, outv);
				deltaPrevPrevPower = deltaPrevPower;
				deltaPrevPower = deltaPower;
				PrevOutV = outv;
				COUNT = 0;
				static_PID_power = 0;
				//RESET
			} else {
				static_PID_power = static_PID_power + card1.getchanelVolt(getC);
				//累加
			}
			return 0;
		}
		static double static_PID_power = 0;


		public CjxtlN() : base()
		{
			pidP = 0.1F;
		}
	}
}
